#ifndef HIGHLIGHTER_HPP
#define HIGHLIGHTER_HPP

#include <QSyntaxHighlighter>
#include <QList>
#include <QTextCharFormat>
#include <QTextDocument>

/**
* @brief Class Highlighter manages the rules for CodeHighlighting
* @details The class manages all available rules to highlight the TextDocument. \n
* New highlighting rules can be added and the highlighting works automatically.
*
* @class Highlighter highlighter.hpp "highlighter.hpp"
*/
class Highlighter : public QSyntaxHighlighter {
    Q_OBJECT

public:
    /**
    * @brief Highlighter Constructor
    *
    * @fn explicit Highlighter(QTextDocument *parent = 0)
    * @param parent
    */
    explicit Highlighter(QTextDocument *parent = 0);

    /**
    * @brief Highlighter Destructor
    *
    * @fn ~Highlighter()
    */
    ~Highlighter();

    /**
    * @brief Add a custom highlighting rule to the internal list
    *
    * @fn void addCustomHighlightingRule(QString s, int type)
    * @param s
    * @param type
    */
    void addCustomHighlightingRule(QString s, int type);

    /**
    * @brief Reset the Highlighter to standard
    *
    * @fn void reset()
    */
    void reset();

    /**
    * @brief Initialize Syntax highlighting and load file with predefined Code words
    *
    * @fn void initialize()
    */
    void initialize();

protected:
    /**
    * @brief Highlight a textblock
    *
    * @fn void highlightBlock(const QString &text)
    * @param text
    */
    void highlightBlock(const QString &text);

private:

    /**
    * @brief HighlightingRule represents all necessary information about a single rule
    *
    * @class HighlightingRule highlighter.hpp "highlighter.hpp"
    */
    struct HighlightingRule {
        QRegExp pattern;
        QTextCharFormat format;
    };

    QList<HighlightingRule> highlightingRules;
    QList<HighlightingRule> additionalRules;

    QTextCharFormat variableFormat;
    QTextCharFormat labelFormat;

signals:
    /**
    * @brief Signal emitted when a new tooltip has been found (in predefined Code word list)
    * @see initialize()
    *
    * @fn void customTooltip(QString item, QString tooltip)
    * @param item
    * @param tooltip
    */
    void customTooltip(QString item, QString tooltip);
};

#endif // HIGHLIGHTER_HPP
